package com.example.foobar.controller;

import com.example.foobar.business.service.DaUserOfficialAccountService;
import com.example.foobar.entity.DaUserOfficialAccount;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DaUserOfficialAccountPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.common.param.IdParam;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户和公众号关系表 控制器
 *
 * @author 郑英奔
 * @since 2021-07-20
 */
@Slf4j
@RestController
@RequestMapping("/daUserOfficialAccount")
@Module("foobar")
@Api(value = "用户和公众号关系表API", tags = {"用户和公众号关系表"})
public class DaUserOfficialAccountController extends BaseController {

    @Autowired
    private DaUserOfficialAccountService daUserOfficialAccountService;

    /**
     * 添加用户和公众号关系表
     */
    @PostMapping("/add")
    @OperationLog(name = "添加用户和公众号关系表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加用户和公众号关系表", response = ApiResult.class)
    public ApiResult<Boolean> addDaUserOfficialAccount(@Validated(Add.class) @RequestBody DaUserOfficialAccount daUserOfficialAccount) throws Exception {
        boolean flag = daUserOfficialAccountService.saveDaUserOfficialAccount(daUserOfficialAccount);
        return ApiResult.result(flag);
    }

    /**
     * 修改用户和公众号关系表
     */
    @PostMapping("/update")
    @OperationLog(name = "修改用户和公众号关系表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改用户和公众号关系表", response = ApiResult.class)
    public ApiResult<Boolean> updateDaUserOfficialAccount(@Validated(Update.class) @RequestBody DaUserOfficialAccount daUserOfficialAccount) throws Exception {
        boolean flag = daUserOfficialAccountService.updateDaUserOfficialAccount(daUserOfficialAccount);
        return ApiResult.result(flag);
    }

    /**
     * 删除用户和公众号关系表
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除用户和公众号关系表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除用户和公众号关系表", response = ApiResult.class)
    public ApiResult<Boolean> deleteDaUserOfficialAccount(@PathVariable("id") Long id) throws Exception {
        boolean flag = daUserOfficialAccountService.deleteDaUserOfficialAccount(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取用户和公众号关系表详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "用户和公众号关系表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "用户和公众号关系表详情", response = DaUserOfficialAccount.class)
    public ApiResult<DaUserOfficialAccount> getDaUserOfficialAccount(@PathVariable("id") Long id) throws Exception {
        DaUserOfficialAccount daUserOfficialAccount = daUserOfficialAccountService.getById(id);
        return ApiResult.ok(daUserOfficialAccount);
    }

}

